package com.example.finger.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.finger.bean.KeyValue;
import com.example.finger.R;

import java.util.List;

/**
 * Created by LYX on 2018/11/27.
 */

public class AddTaskAdapter extends BaseAdapter {
    private List<KeyValue> list;
    private Context context;

    public AddTaskAdapter(List<KeyValue> list,Context context){
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adpter_task_add, null);

            viewHolder = new ViewHolder();
            viewHolder.textViewName = convertView.findViewById(R.id.tv_name);
            viewHolder.textViewData = convertView.findViewById(R.id.tv_data);
            viewHolder.imageView = convertView.findViewById(R.id.imageview);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        KeyValue keyValue = list.get(position);
        viewHolder.textViewName.setText(keyValue.getKey());
        viewHolder.textViewData.setText(keyValue.getValue());
        viewHolder.imageView.setImageResource(keyValue.getDrawable());

        return convertView;
    }

    class ViewHolder {
        public TextView textViewName;
        public TextView textViewData;
        public ImageView imageView;
    }
}
